package dshop.model.permission;

import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import appbase.jfinal.ext.BaseModel;
import dshop.AppConst;

public class PermissionDict extends BaseModel<PermissionDict>{
	
	private static final long serialVersionUID = -6967680902549117464L;
	
	public static final PermissionDict dao = new PermissionDict();

	public static final int LEVEL_ONE = 1;
	
	/**
	 * @return [{id, descs, pId}]
	 */
	public static List<Record> listBy(int level) 
	{
		String sql = "select id, descs, pId from permission_dict where level = ? and isDel = ? order by sortVal asc";
		return Db.find(sql, level, AppConst.DELETE_NO);
	}

	/**
	 * @return [{.., newColumnName = [{id, descs, pId}] }]
	 */
	/*public static void mergeTo(List<Record> list, String pIdColumn, String newColumnName) 
	{
		dao.mergeModelsTo(list, pIdColumn, "id, descs, pId", "pId", newColumnName);
	}*/

	/**
	 * @return [{id, descs, pId}]
	 */
	public static List<Record> childListOf(List<Integer> permIds) 
	{
		if (permIds == null || permIds.isEmpty()) 
		{
			return new ArrayList<Record>();
		}
		
		String sql = "select id, descs, pId from permission_dict where pId in (??) and isDel = ? order by sortVal asc";
		sql = dao.buildSqlHasIn(sql, permIds);
		return Db.find(sql, AppConst.DELETE_NO);
	}

}
